<?php
namespace common\models;


class TradeWithdraw extends BaseModel
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'trade_withdraw';
    }


    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['mch_id', 'b_type', 'multiple', 'to_wechat', 'to_alipay', 'to_bank', 'to_wallet', 'state'], 'integer'],
            [['rate', 'min_num', 'max_num'], 'number'],
            [['update_time'], 'safe'],
            [['condition_group', 'condition_rule'], 'string', 'max' => 128],
            [['describe'], 'string', 'max' => 64],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'mch_id' => '商户id',
            'b_type' => '账本类型',
            'rate' => '手续费比例%',
            'condition_group' => '条件组',
            'condition_rule' => '条件规则',
            'min_num' => '最小提现数量 0不限制',
            'max_num' => '最大提现数量 0不限制',
            'multiple' => '提现倍数 如以100的倍数提现 0不限制',
            'to_wechat' => '提现到微信 1开启 0关闭',
            'to_alipay' => 'To Alipay',
            'to_bank' => 'To Bank',
            'to_wallet' => '提现到钱包',
            'state' => '1可以提现 0不可以提现',
            'describe' => '提示信息',
            'update_time' => 'Update Time',
        ];
    }    

	/*
		* 数据列表
		* whereArr 条件
		* params 基本参数 包含 field order page limit
		* extends  扩展信息 一些相关的信息
		* 
	*/	
	public static function dataList($whereArr, $params, $extends = array())
	{
		$model  = self::find();
		$where  = isset($whereArr['where']) ? $whereArr['where'] : [];
		$whereAnd = isset($whereArr['and'])?$whereArr['and']:[];
		$models = self::queryFormart($model,$where,$params,$whereAnd);
		$model  = $models['model'];
		
		$data  = $model->asarray()->all();
		if(!$data) return array();

		//扩展信息
		if(!$extends) return $data;

		foreach($extends as $extend)
		{

		}

		return $data;	
	}

	public static function getOne($where, $field = ['*'])
	{
		return self::find()->select($field)->where($where)->asarray()->one();
	}


	public static function getAll($where = [], $field = ['*'])
	{
		return self::find()->select($field)->where($where)->asarray()->all();
	}

}